package com.oozol.lieluyun.controller;

import com.oozol.lieluyun.entity.DockerImages;
import com.oozol.lieluyun.entity.ImageTagDel;
import com.oozol.lieluyun.entity.ImageTags;
import com.oozol.lieluyun.entity.RegistryImages;
import com.oozol.lieluyun.entity.ResultData;
import com.oozol.lieluyun.service.IRegistryService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RegistryController {
   @Autowired
   private IRegistryService registryService;

   @GetMapping({"/api/registry/images"})
   public ResultData<List<DockerImages>> getDockerImages() throws Exception {
      List<RegistryImages> images = this.registryService.getImages();
      ResultData res = new ResultData();
      res.setMsg("操作成功");
      res.setCount(images.size());
      res.setPage(1);
      res.setData(images);
      return res;
   }

   @GetMapping({"/api/registry/imageTags"})
   public ResultData<List<ImageTags>> getDockerImageTags(String repositoryName) throws Exception {
      List<ImageTags> images = this.registryService.getImageTags(repositoryName);
      ResultData res = new ResultData();
      res.setMsg("操作成功");
      res.setCount(images.size());
      res.setPage(1);
      res.setData(images);
      return res;
   }

   @PostMapping({"/api/registry/imageTagDel"})
   public ResultData<Integer> delDockerTag(@RequestBody ImageTagDel imageTagDel) throws Exception {
      Integer flag = this.registryService.delImageTag(imageTagDel);
      ResultData res = new ResultData();
      res.setMsg("操作成功");
      res.setData(flag);
      return res;
   }
}
